﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DesktopClient
{
    public partial class RoomList : Form
    {
        private ServerProvider.ServiceSoapClient cl = new DesktopClient.ServerProvider.ServiceSoapClient();
        private string userName;
        private Form parent;

        public RoomList(Form parent, string userName)
        {
			InitializeComponent();
            this.userName = userName;
            this.parent = parent;
            foreach (var item in cl.GetRooms())
				lRoom.Items.Add(item);
            lRoom.SelectedIndex = 0;           
        }

        private void Enter_Click(object sender, EventArgs e)
        {
            cl.EnterRoom(userName, lRoom.SelectedItem.ToString());
            this.Visible = false;
            (new EasyChatClient(this, parent, userName, lRoom.SelectedItem.ToString())).ShowDialog();
        }

        private void Anuluj_Click(object sender, EventArgs e)
        {
            cl.LogOut(userName);
            parent.Visible = true;
            this.Close();
        }

        private void onExit(object sender, FormClosedEventArgs e)
        {
            cl.LogOut(userName);
            parent.Visible = true;
            this.Close();
        }

        private void formSet(object sender, EventArgs e)
        {
            this.Text = "RoomList | User : " + userName;
        }

        private void addRoom_Click(object sender, EventArgs e)
        {
            (new NewRoom(lRoom)).ShowDialog(this);
        }
    }
}
